#include "maintain_labeldelegate.h"

#include <QPainter>
#include <QApplication>
#include <QStyleOption>

MaintainLabelDelegate::MaintainLabelDelegate(QObject *parent) :
    QItemDelegate(parent)
{
}

void MaintainLabelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    if(0 == index.column()) {
        QStyleOptionViewItem labelOption;
        labelOption.rect = option.rect.adjusted(4, 4, -4, -4);
        labelOption.displayAlignment = Qt::AlignCenter;
        labelOption.palette.setColor(QPalette::Text, QColor(Qt::black));
        labelOption.text = "AA";

        painter->save();
        if (option.state & QStyle::State_Selected) {
            painter->fillRect(option.rect, option.palette.highlight());
            painter->setBrush(option.palette.highlightedText());
        }
        QApplication::style()->drawItemText(painter, labelOption.rect, labelOption.displayAlignment, labelOption.palette, true, "BB", QPalette::Text);
//        painter->restore();
    }
    else {
        return QItemDelegate::paint(painter, option, index);
    }
}

bool MaintainLabelDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
{
    return QItemDelegate::editorEvent(event, model, option, index);
}
